<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>        
<script type="text/javascript">	
	$(document).ready(function(){
		//초기에 화면에 뿌려줄 내용
		$("#region_gugunDiv").hide();
		$.ajax({
			type:"POST",
			url:"getSidoList.do",
			dataType:"json",
			success:function(jsonData){	
				//시도 리스트 가져와서 뿌리기
				$("#region_sido option").remove();
				var op="<option value='false'>--</option>";
				$("#region_sido").append(op);
 				$.each(jsonData,function(index){	//jsonData.sidoList을 sidolist란 이름으로 사용
 					op="<option value="+jsonData[index].code_code+">"+jsonData[index].code_name+"</option>";
					$("#region_sido").append(op); 
				});
			}//success
		});//ajax

		$("#region_sido").change(function(){
			var region_sido=$(this).val();
			if(region_sido==false){//시도 값이 바뀌었는데 --을 선택한 경우
				$("#region_gugunDiv").hide();
			}else{						
				$("#region_gugunDiv").show();				
			}
 			$.ajax({
				type:"POST",
				url:"gugunList.do",
				data:"code_code="+region_sido,
				dataType:"json",
				success:function(jsonData){
					
	 				//구군정보 가져와서 뿌리기
					$("#region_gugun option").remove();
					var op="<option value='false'>--</option>";
					$("#region_gugun").append(op);
	 				$.each(jsonData,function(index, codemaster){
	 					op="<option value="+codemaster.code_code+">"+codemaster.code_name+"</option>";
						$("#region_gugun").append(op); 
					});
				}
			}); 
		});
		
		$("#searchForm").submit(function(){
			var region_sido=$("#region_sido").val();
			var region_gugun=$("#region_gugun").val();
			var name=$("#name").val();
			if(region_sido=="false" && region_gugun==null && name==""){
				alert("검색조건 선택없이 검색하시겠습니까?.");
			}else{	//조건에 따른 검색
				$.ajax({
					type:"POST",
					url:"getSearchStudentList.do",
					data:$("#searchForm").serialize(),
					dataType:"json",
					success:function(jsonData){
						alert("검색조건 성공!!");
					}
				});				
			}
			//confirm("전송하시겠습니까?"); 에서 확인을 누르면 전송한다.
			
			//추가 테스트 : name 로 접근하기 위해서는 jquery selector 를 활용
			// alert($("#userAddress").val()); // 정상작동 안됨
			//return confirm("sido : "+sido+"region_gugun : "+region_gugun+"name : "+name+"grade : "+grade+"gender : "+gender+", hopesubject : "+hopesubject+" 검색하시겠습니까?"); 
			//return false; //return false 는 object의 진행을 멈추게 한다.
		});		
	});
</script>

<form id=searchForm action="searchStudentList.do">
<table width="560" cellpadding="2" cellspacing="0"><tr><td>
	<table  >
		<tr>
			<td>희망지역</td>
			<td ><select id = "region_sido"></select></td>
			<td colspan="2"> <span id="region_gugunDiv" ><select id="region_gugun"></select></span></td>
			<td>이름</td><td><input type="text" id="name"></td>
			<td align="right"><input type="submit"  value="검색"> </td>		
		</tr>
	</table>
</td></tr></table>	
</form>
<table width="560" cellpadding="2" cellspacing="0">
	<tr align="right"><td>
		총 학생 수 : ${requestScope.listVO.pagingBean.totalContent}
	</td></tr></table>	
<table width="560"  border="1" cellpadding="2" cellspacing="0">
	<thead>
		<tr><td width="20%">이름</td>
			 <td width="20%">성별</td>
			 <td width="20%">희망지역</td>
			 <td width="20%">희망과목</td>
			 <td width="20%">학교</td>
		</tr>
	</thead>
	<tbody>
			<c:forEach var="mvo" items="${requestScope.listVO.list}">		
			<tr>
			    <td><a href="showContent.do?id=${mvo.id }">${mvo.name }</a></td>			
				<td>${mvo.gender}</td>
				<td>${mvo.hoperegion}</td>
				<td>${mvo.hopesubject}</td>
				<td>${mvo.id}</td>
			</tr>
			</c:forEach>	
	</tbody>	
</table><br>
<table width="560"  cellpadding="2" cellspacing="0"><tr align="center"><td>
<c:set var="pb" value="${requestScope.listVO.pagingBean}"></c:set>
<c:if test="${pb.previousPageGroup}">
	<a href="studentListBasic.do?pageNo=${pb.startPageOfPageGroup-1 }">	Pre </a>
</c:if>	

<c:forEach var="pageNo" begin="${pb.startPageOfPageGroup }" 
										end="${pb.endPageOfPageGroup }">
<c:choose>
<c:when test="${pb.nowPage !=pageNo }" >
	<a href="studentListBasic.do?pageNo=${pageNo }" >${pageNo }</a>
</c:when>
<c:otherwise>
	${pageNo} 
</c:otherwise>
</c:choose>
</c:forEach>

<c:if test="${pb.nextPageGroup}">
	<a href="studentListBasic.do?pageNo=${pb.endPageOfPageGroup+1 }">Next </a>
</c:if>
</td></tr></table>